package com.hdcircles.autoform.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.hdcircles.autoform.R;

/**
 * Created by hdcircles on 2016/9/29.
 */

public class ChoiceAnswerView extends FrameLayout {

    private EditText etAnswer;

    private ImageView ivEdit;

    private boolean isLastItem =true;

    private onEditListener mListener;

    private ChoiceAnswerView answerView;

    public ChoiceAnswerView(Context context) {
        super(context);
        initView();
    }

    public ChoiceAnswerView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public ChoiceAnswerView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    private void initView(){
        answerView=this;
        View view=View.inflate(getContext(), R.layout.view_choice_answer,null);
        etAnswer= (EditText) view.findViewById(R.id.et_answer);
        ivEdit= (ImageView) view.findViewById(R.id.iv_add_or_delete);
        ivEdit.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                mListener.onEdit(answerView);
            }
        });
        addView(view);
    }


    public void setEditListener(onEditListener listener){
        mListener=listener;
    }

    public interface onEditListener {
        void onEdit(View view);
    }
    public EditText getEtAnswer() {
        return etAnswer;
    }

    public void setEtAnswer(EditText etAnswer) {
        this.etAnswer = etAnswer;
    }

    public ImageView getIvEdit() {
        return ivEdit;
    }

    public void setIvEdit(ImageView ivEdit) {
        this.ivEdit = ivEdit;
    }

    public boolean isLastItem() {
        return isLastItem;
    }

    public void setLastItem(boolean lastItem) {
        isLastItem = lastItem;
    }
}
